from django.db import models


# Create your models here.

class LearningResource(models.Model):
    """学习资源模型"""

    # 资源类型选择
    TYPE_CHOICES = [
        ('article', '文章'),
        ('book', '书籍'),
        ('knowledge', '知识'),
        ('trouble', '烦恼'),
    ]

    # 分类选择
    CATEGORY_CHOICES = [
        ('anxiety', '焦虑管理'),
        ('depression', '抑郁应对'),
        ('stress', '压力缓解'),
        ('mindfulness', '正念冥想'),
        ('relationship', '人际关系'),
        ('sleep', '睡眠改善'),
        ('trouble', '成长烦恼'),
        ('knowledge', '青春期知识'),
    ]

    # 基本信息
    title = models.CharField(max_length=200, verbose_name='标题')
    description = models.TextField(verbose_name='描述')
    content = models.TextField(verbose_name='内容')
    type = models.CharField(max_length=20, choices=TYPE_CHOICES, verbose_name='类型')
    category = models.CharField(max_length=20, choices=CATEGORY_CHOICES, verbose_name='分类')

    # 元数据
    duration = models.CharField(max_length=50, verbose_name='阅读时长')
    rating = models.DecimalField(max_digits=3, decimal_places=1, verbose_name='评分')
    file_size = models.CharField(max_length=20, blank=True, null=True, verbose_name='文件大小')
    download_url = models.URLField(blank=True, null=True, verbose_name='下载链接')

    # 时间戳
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        verbose_name = '学习资源'
        verbose_name_plural = '学习资源'
        ordering = ['-created_at']

    def __str__(self):
        return self.title
